#ifdef IP_108

	.syntax	unified
	//.arch	armv6-m
	.cpu cortex-m0


/* Stack define --------------------------------------------------------------*/
	.section .stack
	.align	3
	.equ	Stack_Size, 0x1000

	.globl	__StackTop
	.globl	__StackLimit
__StackLimit:
	.space	Stack_Size
	.size	__StackLimit, . - __StackLimit
__StackTop:
	.size	__StackTop, . - __StackTop


/* Heap define ---------------------------------------------------------------*/
	.section .heap
	.align	3
	.equ	Heap_Size, 0x8

	.globl	__HeapBase
	.globl	__HeapLimit
__HeapBase:
	.if	Heap_Size
	.space	Heap_Size
	.endif
	.size	__HeapBase, . - __HeapBase
__HeapLimit:
	.size	__HeapLimit, . - __HeapLimit


/* Vector --------------------------------------------------------------------*/
	.section .isr_vector
	.align 2
	.globl	__isr_vector
__isr_vector:
	.long	__StackTop            /* Top of Stack */
	.long	Reset_Handler         /* Reset Handler */
	.long	NMI_Handler           /* NMI Handler */
	.long	HardFault_Handler     /* Hard Fault Handler */
	.long	0                     /* Reserved */
	.long	0                     /* Reserved */
	.long	0                     /* Reserved */
	.long	0                     /* Reserved */
	.long	0                     /* Reserved */
	.long	0                     /* Reserved */
	.long	0                     /* Reserved */
	.long	SVC_Handler           /* SVCall Handler */
	.long	0                     /* Reserved */
	.long	0                     /* Reserved */
	.long	PendSV_Handler        /* PendSV Handler */
	.long	SysTick_Handler       /* SysTick Handler */

	/* External interrupts */
    .long     I2C0_IRQHandler            @ 0,
    .long     SPI0_IRQHandler            @ 1,
    .long     I2S_IRQHandler             @ 2,
    .long     UART0_IRQHandler           @ 3,
    .long     PWM0_IRQHandler            @ 4,
    .long     ADC_IRQHandler             @ 5,
    .long     WDT_IRQHandler             @ 6,
    .long     WWDT_IRQHandler            @ 7,
    .long     TMR0_IRQHandler            @ 8,
    .long     ACC_IRQHandler             @ 9,
    .long     SPI1_IRQHandler            @ 10,
    .long     LL_IRQHandler              @ 11,
    .long     UART1_IRQHandler           @ 12,
    .long     TMR1_IRQHandler            @ 13,
    .long     TMR2_IRQHandler            @ 14,
    .long     TRIM_IRQHandler            @ 15,
    .long     KSCAN_IRQHandler           @ 16,
    .long     QDEC_IRQHandler            @ 17,
    .long     GPIO_IRQHandler            @ 18,
    .long     PWM1_IRQHandler            @ 19,
    .long     PWM2_IRQHandler            @ 20,
    .long     USBDMA_IRQHandler          @ 21,
    .long     USB_IRQHandler             @ 22,
    .long     0                          @ 23,
    .long     EXT0_IRQHandler            @ 24,
    .long     EXT1_IRQHandler            @ 25,
    .long     EXT2_IRQHandler            @ 26,
    .long     DMA_IRQHandler             @ 27,
    .long     BOD_IRQHandler             @ 28,
    .long     SLEEP_IRQHandler           @ 29,
    .long     STANDBY_IRQHandler         @ 30,
    .long     MODEM_IRQHandler           @ 31,

	.size	__isr_vector, . - __isr_vector


	.weak     I2C0_IRQHandler            @ 0,
    .weak     SPI0_IRQHandler            @ 1,
    .weak     I2S_IRQHandler             @ 2,
    .weak     UART0_IRQHandler           @ 3,
    .weak     PWM0_IRQHandler            @ 4,
    .weak     ADC_IRQHandler             @ 5,
    .weak     WDT_IRQHandler             @ 6,
    .weak     WWDT_IRQHandler            @ 7,
    .weak     TMR0_IRQHandler            @ 8,
    .weak     ACC_IRQHandler             @ 9,
    .weak     SPI1_IRQHandler            @ 10,
    .weak     LL_IRQHandler              @ 11,
    .weak     UART1_IRQHandler           @ 12,
    .weak     TMR1_IRQHandler            @ 13,
    .weak     TMR2_IRQHandler            @ 14,
    .weak     TRIM_IRQHandler            @ 15,
    .weak     KSCAN_IRQHandler           @ 16,
    .weak     QDEC_IRQHandler            @ 17,
    .weak     GPIO_IRQHandler            @ 18,
    .weak     PWM1_IRQHandler            @ 19,
    .weak     PWM2_IRQHandler            @ 20,
    .weak     USBDMA_IRQHandler          @ 21,
    .weak     USB_IRQHandler             @ 22,
    /*.weak     0                           23,*/
    .weak     EXT0_IRQHandler            @ 24,
    .weak     EXT1_IRQHandler            @ 25,
    .weak     EXT2_IRQHandler            @ 26,
    .weak     DMA_IRQHandler             @ 27,
    .weak     BOD_IRQHandler             @ 28,
    .weak     SLEEP_IRQHandler           @ 29,
    .weak     STANDBY_IRQHandler         @ 30,
    .weak     MODEM_IRQHandler           @ 31,


/* Reset_Handler -------------------------------------------------------------*/
	.text
	.thumb
	.thumb_func
	.align	1
	.globl	Reset_Handler
	.type	Reset_Handler, %function
Reset_Handler:

/*  Single section scheme.
 *
 *  The ranges of copy from/to are specified by following symbols
 *    __etext:        LMA of start of the section to copy from. Usually end of text
 *    __data_start__: VMA of start of the section to copy to
 *    __data_end__:   VMA of end of the section to copy to
 *
 *  All addresses must be aligned to 4 bytes boundary.
 */
	ldr	    r1, =__etext
	ldr  	r2, =__data_start__
	ldr	    r3, =__data_end__

	subs	r3, r2
	ble	   .L_loop1_done

.L_loop1:
	subs	r3, #4
	ldr  	r0, [r1,r3]
	str	    r0, [r2,r3]
	bgt	    .L_loop1

.L_loop1_done:


/**
 * ram code section copy
 */
#if 1
	ldr  	r1, =__eramcode
	ldr	    r2, =__ram_code_start__
	ldr	    r3, =__ram_code_end__

	subs	r3, r2
	ble	    .L_loop2_done

.L_loop2:
	subs	r3, #4
	ldr	    r0, [r1,r3]
	str	    r0, [r2,r3]
	bgt	    .L_loop2

.L_loop2_done:
#endif

/*  Single BSS section scheme.
 *
 *  The BSS section is specified by following symbols
 *    __bss_start__: start of the BSS section.
 *    __bss_end__:   end of the BSS section.
 *
 *  Both addresses must be aligned to 4 bytes boundary.
 */
	ldr  	r1, =__bss_start__
	ldr	    r2, =__bss_end__

	movs	r0, 0

	subs	r2, r1
	ble	   .L_loop3_done

.L_loop3:
	subs	r2, #4
	str		r0, [r1, r2]
	bgt		.L_loop3

.L_loop3_done:

	/* system init. */
	bl	SystemInit

#ifndef __START
#define __START _start
#endif
	/* enter main */
	bl	main//__START

	.pool
	.size	Reset_Handler, . - Reset_Handler

	.align	1
	.thumb_func
	.weak	Default_Handler
	.type	Default_Handler, %function
Default_Handler:
	b	.
	.size	Default_Handler, . - Default_Handler

/*    Macro to define default handlers. Default handler
 *    will be weak symbol and just dead loops. They can be
 *    overwritten by other handlers */
	.macro	def_irq_handler	handler_name
	.weak	\handler_name
	.set	\handler_name, Default_Handler
	.endm

	def_irq_handler	NMI_Handler
	def_irq_handler	HardFault_Handler
	def_irq_handler	SVC_Handler
	def_irq_handler	PendSV_Handler
	def_irq_handler	SysTick_Handler
	def_irq_handler	DEF_IRQHandler

	.end

#endif
